package app.actions;

import java.awt.event.ActionEvent;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Locale;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.JOptionPane;

/**
 *  Akce zmeny aktivniho jazyku aplikace
 * @author Dejvino
 */
public class ChangeLanguageAction extends AbstractAction{

    public void actionPerformed(ActionEvent ae) {
        System.out.println("New locale: " + ae.getActionCommand());
        Locale.setDefault(new Locale(ae.getActionCommand()));

        // ulozeni noveho nastaveni
        Properties p = new Properties();
        try {
            p.load(new FileInputStream("settings.properties"));
            p.setProperty("locale", ae.getActionCommand());
            p.store(new FileOutputStream("settings.properties"), "Program settings");
            JOptionPane.showConfirmDialog(null,
                java.util.ResourceBundle.getBundle("app/frames/language").getString("LocaleChangeMSG"),
                java.util.ResourceBundle.getBundle("app/frames/language").getString("LanguageChange"),
                JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
        } catch (IOException ex) {
            Logger.getLogger(ChangeLanguageAction.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}
